package com.ybkj.o2o.mc.controller.v4;

import com.ybkj.o2o.mc.common.transport.Error;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;

public class ResultTransport implements Serializable {

  private static final long serialVersionUID = 1L;

  private int code;

  private String message;

  private Object data;

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  /**
   * 快速获取ResultTransport对象.
   *
   * @param error 错误信息
   */
  @JsonIgnore
  public static ResultTransport getErrorBy(Error error) {

    ResultTransport instance = new ResultTransport();
    instance.setCode(error.getCode());
    instance.setMessage(error.getMessage());

    return instance;
  }

  @Override
  public String toString() {
    return "ResultTransport{" +
            "code=" + code +
            ", message='" + message + '\'' +
            ", data=" + data +
            '}';
  }
}
